package com.qixin.total.controller;


import com.qixin.api.bean.ResultPage;
import com.qixin.api.bean.TotalRole;
import com.qixin.api.bean.VoPage;
import com.qixin.api.service.TotalRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author 李许多
 * @since 2018-11-12
 */
@Controller
@RequestMapping("/totalRole")
public class TotalRoleController {
    @Autowired
    TotalRoleService totalRoleService;

    //子页面请求
    @RequestMapping("/main.html")
    public String home(){
        return "/power/role";

    }
    //查询所有角色  如果带分页参数 就分页  如果不带分页参数  就不分页
    @RequestMapping("/findRole")
    @ResponseBody
    public ResultPage<TotalRole> findRole(VoPage voPage,TotalRole totalRole){
        ResultPage<TotalRole> resultPage=totalRoleService.selectMyPage(voPage,totalRole);
        return resultPage;
    }
    //删除
    @RequestMapping("/deleteRole")
    @ResponseBody
    public String deleteRole(Long id)   {
        try {
            return totalRoleService.deleteRole(id);
        } catch (SQLException e) {
            return "删除失败";
        }
    }
    @RequestMapping("/Role_add")
    public String Role_add (){
        return "/power/Role_add";
    }

    //新增角色  和菜单关联
    @RequestMapping("/insertRole")
    @ResponseBody
    public String insertRole( String param){
        if(totalRoleService.insertRoleAndMenu(param)){
            return  "新增成功";
        }
        return "服务器错误...请稍后再试";
    }
}
